package com.bw.conkz;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.bean.T1;
import com.bw.bean.T2;
import com.bw.sever.SeverDao;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class Conkz {
    @Resource
    SeverDao severDao;
    @RequestMapping("/aa")
    public JSONObject a(){
        List<T1> show = severDao.show();
        JSONObject o1 = new JSONObject();
        o1.put("status",0);
        o1.put("msg","");

        JSONObject o2 = new JSONObject();

        JSONArray a1 = new JSONArray();
        JSONObject aa1 = new JSONObject();
        aa1.put("name","视频播放次数");
        aa1.put("id","a");
        a1.add(aa1);

        JSONObject aa2 = new JSONObject();
        aa2.put("name","累计播放时长");
        aa2.put("id","b");
        a1.add(aa2);

        JSONObject aa3 = new JSONObject();
        aa3.put("name","观看人数");
        aa3.put("id","c");
        a1.add(aa3);

        JSONObject aa4 = new JSONObject();
        aa4.put("name","人均观看时长");
        aa4.put("id","d");
        a1.add(aa4);

        o2.put("columns",a1);

        JSONArray oo1 = new JSONArray();
        for (T1 t1 : show) {
            JSONObject object = new JSONObject();
            object.put("a",t1.getA());
            object.put("b",t1.getB());
            object.put("c",t1.getC());
            object.put("d",t1.getD());

            oo1.add(object);
        }
        o2.put("rows",oo1);
        o1.put("data",o2);
        return o1;
    }
    @RequestMapping("/bb")
    public JSONObject b() {
        List<T2> t2s = severDao.show1();
        JSONObject object = new JSONObject();
        object.put("status",0);
        object.put("msg","");

        JSONObject o1 = new JSONObject();
        JSONArray a1 = new JSONArray();
        for (T2 t2 : t2s) {
            JSONObject object1 = new JSONObject();
            object1.put("name",t2.getName());
            object1.put("value",t2.getJe());
            a1.add(object1);
        }
        o1.put("mapData",a1);
        object.put("data",o1);


        return object;
    }
}
